'use strict'
/**
 * 角色管理控制类
 */
const Controller = require('egg').Controller;
class RoleController extends Controller {

  async index() {
    const { ctx } = this;
    let page = ctx.query.page || 1;
    let result = await ctx.service.role.getRolePageList(page);
    ctx.body = result;
  }

  async save() {
    const { ctx } = this;
    let data = ctx.request.body;
    let result = await ctx.service.role.saveRole(data);
    ctx.body = result;
  }

  async delete() {
    const { ctx, logger } = this;
    let id = ctx.query.id;
    logger.info('***id***{}=>', id)
    let result = await ctx.service.role.deleteRole(id);
    ctx.body = result;
  }

  async getList(){
    const {ctx} = this;
    let result = await ctx.service.role.getRoleList();
    ctx.body = result;
  }

  async getPermissionByRoleId(){
    const {ctx} = this;
    let id = ctx.query.id;
    let result = await ctx.service.role.getPermissionByRoleId(id);
    ctx.body = result;
  }

  async saveNewPermissionsByRoleId(){
    const {ctx,logger} = this;
    let data = ctx.request.body;
    logger.info('data',data)
    let result = await ctx.service.role.saveNewPermissionsByRoleId(data);
    ctx.body = result;
  }
}

module.exports = RoleController;
